package viewmodel;

import items.EntityItem;
import model.Entity;
import android.app.betmein.R;
import android.app.betmein.view.EntityMembersView;
import android.app.betmein.view.ViewCreatorHelper;
import android.content.Context;
import android.framework.binding.BindableList;
import android.framework.binding.Binding;
import android.framework.binding.ItemList;
import android.framework.paging.BaseViewModel;

public class EntityMembersViewModel extends BaseViewModel<EntityMembersView>{

	private Entity entity;
	private ItemList<EntityItem> members;
	
	public EntityMembersViewModel(Context context, Entity entity) {
		super(context);
		this.setEntity(entity);
		members = new ItemList<EntityItem>(context, R.layout.item_entity, ViewCreatorHelper.entityListViewCreator());
	}

	@Override
	public void onInit() {
		getView().members.setAdapter(members);
	}

	public Entity getEntity() {
		return entity;
	}

	public void setEntity(Entity entity) {
		this.entity = entity;
	}
	
	public void setMembers(BindableList<EntityItem> members) {
		
		this.members.clear();
		this.members.addAll(members);
		Binding.attached(members, this.members);
		
	}

}
